package org.huangrui.javase.api;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * @Author hr
 * @Create 2025-11-07 11:18
 **/
public class T02String {
    public static void main(String[] args) throws UnsupportedEncodingException {
        // test1();
        testEnOrDecode();
    }

    private static void testEnOrDecode() throws UnsupportedEncodingException {
        String str = "love尚硅谷";

        byte[] bytes = str.getBytes("GBK");
        System.out.println(Arrays.toString(bytes));

        String result = new String(bytes,"GBK");
        System.out.println("result = " + result);

        System.out.println("===============");

        byte[] bytes2 = str.getBytes("UTF-8");
        System.out.println(Arrays.toString(bytes2));

        String result2 = new String(bytes2, "UTF-8");
        System.out.println("result2 = " + result2);

        System.out.println("=====================");
        String result3 = new String(bytes, "UTF-8");
        System.out.println("result3 = " + result3);
    }

    private static void test1() {
        String s1 = "hello";
        String s2 = "love尚";
        System.out.println(s1);
        System.out.println(s2);
    }
}
